package com.useeinfo.oa.modules.maintaining.entity;

import com.alibaba.fastjson.JSONObject;
import com.useeinfo.framework.extend.entity.SuperClassEntity;
import com.useeinfo.framework.sugar.tools.StringConverters;
import com.useeinfo.oa.modules.base.entity.Enterprise;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/**
 * 维保应用场景表
 */
@Entity
@Table(name = "application_scenarios")
public class ApplicationScenarios extends SuperClassEntity<ApplicationScenarios> {
    /**
     * 名称
     */
    private String name;
    /**
     * 描述
     */
    private String description;
    /**
     * 所属企业
     */
    @ManyToOne
    @JoinColumn(name = "enterprise_id")
    private Enterprise enterprise;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Enterprise getEnterprise() {
        return enterprise;
    }

    public void setEnterprise(Enterprise enterprise) {
        this.enterprise = enterprise;
    }

    @Override
    public JSONObject toJSONObject() {
        JSONObject jsonObject = super.toJSONObject();
        jsonObject.put("name", StringConverters.null2String(getName()));
        jsonObject.put("description", StringConverters.null2String(getDescription()));
        if(getEnterprise()!=null){
            jsonObject.put("enterpriseName", StringConverters.null2String(getEnterprise().getEnterpriseName()));
        }else{
            jsonObject.put("enterpriseName", "");
        }
        return jsonObject;
    }
}
